<div class="layui-fluid layui-anim febs-anim" id="businesses-reqInfo" lay-title="请求异常管理">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="reqInfo-table-form">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">开始时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="startDate" id="dtpStartDate_ReqInfo" lay-verify="date"
                                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">结束时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="endDate" id="dtpEndDate_ReqInfo" lay-verify="date"
                                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">触发方式</label>
                                        <div class="layui-input-inline">
                                            <select name="triggerType" lay-verify="" id="cboTriggerType_ReqInfo">
                                                <option value="0" selected>请选择</option>
                                                <option value="62" >定时器同步</option>
                                                <option value="63" >手动同步</option>
                                                <option value="64" >自动推送</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">请求人</label>
                                        <div class="layui-input-inline">
                                            <select name="reqUserId" lay-verify="" lay-search id="cboReqUserId_ReqInfo">
                                                <option value="0">请选择</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query_ReqInfo">
                                    <i class="layui-icon">&#xe848;</i><!--查询放大镜图标-->
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset_ReqInfo">
                                    <i class="layui-icon">&#xe79b;</i><!--重置刷新图标-->
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            <div class="layui-row">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="export_ReqInfo">
                                    <i class="layui-icon layui-icon-export">导出</i>
                                </div>
                            </div>
                        </blockquote>
                    </form>
                    <table lay-filter="reqInfoTable" lay-data="{id: 'reqInfoTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="reqInfo-option">
    <a lay-event="detail"><i class="layui-icon febs-edit-area febs-green">&#xe864;</i></a><!--下载图标-->
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs', 'laydate'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            laydate = layui.laydate,
            $view = $('#businesses-reqInfo'),
            $query = $view.find('#query_ReqInfo'),
            $add = $view.find('#add'),
            $reset = $view.find('#reset_ReqInfo'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createDate', type: null},
            tableIns;


        form.render();

        /*
        *  开始日期、结束日期控件渲染
        * */
        laydate.render({
            elem: '#dtpStartDate_ReqInfo',
        });
        laydate.render({
            elem: '#dtpEndDate_ReqInfo'
        });


        initTable();


        table.on('sort(reqInfoTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            console.log(params);
            tableIns.reload({where: params, page: {curr: 1}});
        });


        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'reqInfoTable',
                url: ctx + 'reqInfo/list',
                cols: [[
                    {field: 'id',title: 'id',type: 'checkbox'},
                    {field: 'reqTime', title: '请求时间', minWidth: 100, sort: true},
                    {field: 'url', title: '请求地址', minWidth: 100},
                    {field: 'triggerTypeName', title: '触发方式'},
                    {field: 'reqUserName', title: '请求人', minWidth: 50 ,
                        templet: function(d){
                            if(d.reqUserId <= 0 ){
                                if(d.reqUserId == -1){
                                    return "系统【自动推送】";
                                }else if(d.reqUserId == 0){
                                    return "系统【定时器同步】";
                                }
                            }else {
                                return d.reqUserName;
                            }
                        }
                    },
                    {field: 'respStatusInfo', title: '请求异常说明', minWidth: 180},
                    {title: '操作', toolbar: '#reqInfo-option', minWidth: 140}
                ]]
            });
            initCboReqUserId();
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
//            console.log(params);
            return params;
        }


        /*
        * 加载请求人下拉菜单
        * */
        function initCboReqUserId() {
            $.ajax({
                type:"GET",
                url: ctx + 'user/reqUserList',

                success:function (res) {
                    for(var i = 0 ;i < res.length;i++){
                        var htmlContent = "<option value='"+ res[i].userId +"' >" + res[i].username + "</option>";
//                        console.log(htmlContent);
                        $("#cboReqUserId_ReqInfo").append(htmlContent);
                    }
                    form.render();
                }
            });
        }
    })
</script>